import json
from pathlib import Path
from .config import get_aps_path  # 新增导入

class APSParser:
    def __init__(self):
        self.apsPath = get_aps_path()  # 使用配置函数
        self.subSystems = {}
        self.loadSubSystems()

    def loadSubSystems(self):
        """加载所有音频处理子系统"""
        for filePath in self.apsPath.glob("*.json"):
            try:
                with open(filePath, 'r', encoding='utf-8') as f:
                    data = json.load(f)
                    systemType = data.get('type')
                    if systemType:
                        self.subSystems[systemType] = data
            except Exception as e:
                print(f"加载子系统文件 {filePath} 时出错: {e}")

    def getSubSystem(self, systemType):
        """获取指定类型的子系统"""
        return self.subSystems.get(systemType)

    def getAllSubSystems(self):
        """获取所有子系统"""
        return self.subSystems